Skip to content

fix(portfolio-import): 数量/成本尾随百分号改为需人工确认 - #413

Merged
helsome merged 2 commits into
helsome:mainfrom
wannT-1:fix/portfolio-import-percent
Nov 12, 2026
Merged

helsome merged 2 commits into
helsome:mainfrom
wannT-1:fix/portfolio-import-percent

Conversation

@wannT-1

@wannT-1 wannT-1 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

改动说明

What

按 review 意见调整:toFiniteNumber 在去掉千分位、$ 和空白之后,若剩余文本是纯数字加一个尾随 %(如 100%、12.5%),不再静默解析为 100 / 12.5 入账。数量、成本留空,该行走现有复核路径:

  • issues 记为 Quantity "100%" needs confirmation 或 Cost price "12.5%" needs confirmation
  • confidence 为 0.6(需要复核);若 symbol 已模糊则为 0.3
  • draft.warnings 仍会标记该行需要 review

不新增 UI。1,000、$180.50、1,234.56等原有解析不变。100%%、10%5 仍视为非法数值。

Why

数量/成本里的 % 不能无条件视为装饰字符。100%、12.5% 也可能是比例或错误列映射;静默按 100、12.5 入账的风险,高于拒绝解析并交给用户确认。目前没有经过核对的券商导出样本与字段契约,因此走「需要人工确认」路径。

不改表头映射,也不处理货币前缀、会计括号、全角数字或零宽字符(#356–#360 的范围)。

关联 Issue

Closes #409

测试报告(正式审核前必填)

环境

  • Bun:1.4.2
  • OS:Linux 6.12.94+ x86_64

实际执行命令与结果

bun test packages/shared/src/portfolio-import
→ 109 pass / 0 fail
→ 321 expect() calls
→ Ran 109 tests across 4 files

bun run --cwd packages/shared typecheck
→ tsc --noEmit,exit 0

已知失败 / Baseline(如有)

无失败。

  • 已提供实际测试命令与 pass/fail 结果
  • 已说明测试环境
  • 如果存在已知 baseline / 环境失败,已提供 main 对照或说明
  • 核心改动已有对应 focused test / smoke / integration 验证

UI 截图(仅可见 UI 变化时必填)

  • 本 PR 无可见 UI 变化(无需截图)
  • 本 PR 有可见 UI 变化,已提供修改后的 UI 截图
  • 已提供 Before / After 对比截图(适用时)

Scope / 后续

只处理数量/成本上「纯数字 + 一个尾随 %」,改为需人工确认,不静默入账。不把百分号列自动当成权重。

@helsome helsome left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 % 不能在持仓数量/成本字段中无条件视为装饰字符。100%、12.5% 也可能是比例或错误列映射;直接按 100、12.5 入账,会把原本应提示用户修正的输入静默转成真实持仓,风险高于拒绝解析。请提供明确的券商导出样本与字段契约,或将这类单元格标记为需要人工确认;在此之前不建议合并。

100% 与 12.5% 不再按数字入账。这类单元格记入 issues 并降为需复核,避免把比例或错列静默写成真实持仓。

Co-authored-by: wannT-1 <[email protected]>
@wannT-1 wannT-1 changed the title fix(portfolio-import): 剥离数量/成本尾随百分号 fix(portfolio-import): 数量/成本尾随百分号改为需人工确认 Nov 12, 2026

wannT-1 commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

感谢 review。已按你的建议改了:在没有经过核对的券商导出样本之前,不再把数量/成本里的尾随 % 静默入账。

100%、12.5% 现在会留空,并在现有复核行上标记需要确认(issues 为 Quantity "100%" needs confirmation / Cost price "12.5%" needs confirmation,confidence 0.6)。1,000、$180.50 等原有解析不受影响。100%%、10%5 仍视为非法数值。

测试:bun test packages/shared/src/portfolio-import → 109 pass / 0 fail;bun run --cwd packages/shared typecheck → exit 0。

Commit:55379a17

@helsome
helsome dismissed their stale review November 12, 2026 07:04

作者已在 55379a1 修复先前阻断:百分比数量/成本不再按数字静默入账,而是保留复核警告;相关解析、draft 和持久化回归已补齐。原 REQUEST_CHANGES 不再适用。

@helsome
helsome merged commit e42e927 into helsome:main Nov 12, 2026
wannT-1 added a commit to wannT-1/folio that referenced this pull request Nov 17, 2026
Resolve conflicts from helsome#413 (trailing-percent confirmation) and helsome#414
(semicolon CSV) landing upstream:

- toFiniteNumber now runs the branch's normalisation pipeline
  (stripInvisible -> foldNumericWidth -> takeAccountingSign ->
  stripCurrencyAffixes) and feeds the result into upstream's
  stripNumericDecorations, so the trailing-% semantics added by helsome#413
  are preserved instead of reverting them.
- Symbol length is 1-6 upstream already, so the branch's 1-6 change and
  its docs were dropped rather than re-applied.
- Tests: kept this branch's currency / accounting-negative / fullwidth /
  zero-width cases and upstream's percent-confirmation cases.

packages/shared/src/portfolio-import: 125 pass, 0 fail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(portfolio-import): 数量/成本单元格尾随 % 无法解析为数值

2 participants